package cn.bone.chapter08;

/**
 * 栈上分配测试
 * -Xmx1G -Xms1G -XX:-DoEscapeAnalysis -XX:+PrintGCDetails
 *
 * 开启逃逸分析
 * -Xmx1G -Xms1G -XX:+DoEscapeAnalysis -XX:+PrintGCDetails
 */
public class StackAllocation {

    public static void main(String... args){

        long start = System.currentTimeMillis();

        for(int i=0; i<10000000; i++){
            alloc();
        }

        long end = System.currentTimeMillis();

        System.out.println("花费的时间为: " + (end - start) + "  ms");

        // 为了方便查看堆内存中对象个数，线程sleep
                try {
            Thread.sleep(1000000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void alloc(){
        User user = new User();
    }

    static class User {

    }
}
